package org.september.pisces.imagesearch.service;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.september.pisces.imagesearch.vo.FeatureInfo;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@Service
public class FeatureStoreService {

	private String Feature_Data_File_Path = "./feature.data";
	
	private List<FeatureInfo> features = new ArrayList<>();
	
	public void add(FeatureInfo feature) {
		if(features.contains(feature)) {
			return;
		}
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jsonStr = gson.toJson(feature);
        try {
			FileUtils.writeStringToFile(new File(Feature_Data_File_Path), jsonStr, "utf8",true);
		} catch (IOException e) {
			e.printStackTrace();
		}
        features.add(feature);
	}

	public List<FeatureInfo> getFeatures() {
		return features;
	}
	
}
